/**
 * Created by Administrator on 2025/5/8.
 * */
#ifndef MAINCONTROLLER_ERA
#define MAINCONTROLLER_ERA

#include "TaskModule.h"
#include "../GlobalParameters.h"
#include <iostream>
#include <thread>
#include <chrono>
#include <vector>
#include <string>
#include <zmq.hpp>
#include "../include/zy_net.h"

extern "C" BaseObject *createMainController();
extern "C" void destroyMainController(BaseObject *p);

typedef struct HostVo_ {
    std::string host;
    int port;
    HostVo_(std::string host, int port) {
        this->host = host;
        this->port = port;
    }
} HostVo;

class MainController : public TaskModule {
public:
    MainController();
    ~MainController();
    void onCompute(buffer_table_t *input, buffer_table_t *output) override;
    void serveAisZR(); // AI控制相关服务器
    // AI模块控制命令处理函数
    int updateAmState(int cmdLen, const uint8_t *pCmdData, int& ackId, int& ackLen, uint8_t **ppAckData);

private:
    int step;
    zmq::context_t ctx;
    zmq::socket_t pub;
    std::string topicAddr = "tcp://192.168.1.115:6001";
    std::string topicName = "MainController";
    // AI控制相关服务端
    zmq::socket_t zrSockAis;
    std::string zrAddrAis = ZR_AIS;

















    int sock;
    std::vector<HostVo> hosts;
    int startup();
    int demo();
    // 处理程序
    int dataSource();
    int traditionAlgorithm();
    int dataCenter();
    int aiNodeInfer();
    int aiE2EInfer();
    int aiPCTrain();
    int aiCFARTrain();
    int aiE2ETrain();

    // 目标数据
    float range = 150.0;
    float dr = 0.3;
    float da = 0.02;
    float velocity = 20.0;
    float theta = 35.0;
    float phi = 39.2;
    float errorRate0 = 0.1002; // 传统算法误差
    float errorRate11 = 0.3; // 刚开始上线时AINodeInfer的误差
    float errorRate12 = 0.3; // 刚开始上线时AIE2EInfer的误差
    float errorRate21 = 0.1; // 第一次升级后AINodeInfer的误差
    float errorRate22 = 0.1; // 第一次升级后AIE2EInfer的误差
    float errorRate31 = 0.05; // 识别出跟传统算法差异并训练升级后AINodeInfer的误差
    float errorRate32 = 0.05; // 识别出跟传统算法差异并训练升级后AIE2EInfer的误差
    float errorRate41 = 0.01; // 识别出真值目标并训练升级后AINodeInfer的误差
    float errorRate42 = 0.01; // 识别出真值目标并训练升级后AIE2EInfer的误差
    float errorRate51 = 0.0; // 自监督算法训练升级后AINodeInfer的误差
    float errorRate52 = 0.0; // 自监督算法训练升级后AIE2EInfer的误差
};

#endif //TASK1_ERA
